< previous page page_620 next page >

Page 620
You may be familiar with the DBGrid control from previous versions of Visual Basic. Unlike that control, the DataGrid control is designed for use with the newer ActiveX Data Objects (ADO). Instead of the older Data control, the DataGrid is bound to the new ADO Data control, discussed earlier in this chapter.
A sample use of the data grid is shown in Figure 28.9. This grid is set up to display a view of the Titles table of the BIBLIO sample database included with Visual Basic.
0620-01.jpg
Figure 28.9
This DataGrid control uses a recordset
provided by the ADO Data control.
The data grid is a fairly easy control to use, despite the fact that you not only have to understand how it works, but you also have to attach it to a database. Before you can use the DataGrid, however, you must add it to Visual Basic Toolbox. To do so, right-click in an empty area of the Toolbox, select Components from the context menu, and add the control called Microsoft DataGrid Control 6.0. Click OK to close the Components dialog box.
Getting Data into the Grid
To use the DataGrid, you have set up the grid to look the way you want and bind it to a data source. Binding the DataGrid is similar to working with other bound controls, as you can see in these steps:
1. Draw an ADO Data control on the form with the DataGrid, and set it up as described earlier in the section "Using the ADO Data Control."
2. Display the Properties window for the DataGrid, and set the DataSource property to the name of the ADO Data control. (Notice that no DataField property exists, because unlike other controls, the DataGrid displays multiple fields.)
3. The DataGrid can configure its columns automatically based on the data source. Simply right-click the control, and choose Retrieve Fields from the context menu. The layout of the grid changes to include fields from the ADO Data control.
4. Customize the layout of the grid, and perform any desired manual configuration.
sarrow.gifSee "Getting Acquainted with Bound Controls," p. 550

 
< previous page page_620 next page >